import { IsDefined, IsInt, IsNotEmpty, IsString, Length } from "class-validator";
import { BaseEntity } from "@/common/BaseEntity";
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { TStatus } from "@/common/CommonType";
import SysUserEntity from "../user/Entity";

@Entity({
  name: "sys_dept",
  orderBy: { createTime: "DESC" }
})
export default class SysDeptEntity extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id: number;

  /**
   * 部门名称
   */
  @Length(2, 20)
  @IsString()
  @IsNotEmpty()
  @IsDefined()
  @Column({
    nullable: true
  })
  public name: string;

  /**
   * 上级部门id 
   */
  @IsInt()
  @Column({
    nullable: true
  })
  public parentId: number;

  /**
   * 备注
   */
  @IsString()
  @Column({
    nullable: true
  })
  public remark: string;

  @IsInt()
  @IsNotEmpty()
  @IsDefined()
  @Column({
    nullable: true
  })
  public status: TStatus;

  /**
   * 用户
   */
  @OneToOne(() => SysUserEntity)
  user: SysUserEntity

  public static transform(plainObject: object): SysDeptEntity {
    return super.baseTransform(SysDeptEntity, plainObject);
  }
}